﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using VswService_V7.Utility;

namespace VswService_V7.DataBase.Tables.L3INTERFACE
{
    public class L3INTF_EVENT
    {
        #region public field
        public static readonly string tableName = "L3INTF_EVENT";
        public static readonly string fd_eventNo = "EVENT_NO";
        public static readonly string fd_eventCode = "EVENT_CODE";
        public static readonly string fd_eventDate = "EVENT_DATE";
        public static readonly string fd_eventStatus = "EVENT_STATUS";
        public static readonly string fd_operator = "OPERATOR";
        public static readonly string fd_errorInfo = "ERROR_INFO";
        #endregion
        #region EventCode
        public const string generalTask = "3001";
        public const string deleteTask = "3002";
        public const string updateTask = "3003";
        public const string addStripstoTask = "3004";
        public const string deleteStripfromTask = "3005";
        public const string updateStrip = "3006";
        public const string requestBatchNo = "3011";
        public const string checkConnect = "3900";
        #endregion
        /// <summary>
        /// get eventid and eventcode when eventstate=0
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> MonitorL3Infc_Event()
        {
            try
            {
                Dictionary<string, string> dicL3Event = new Dictionary<string, string>();
                string sql = string.Format("select * from {0} where {1}=1", tableName, fd_eventStatus);
                DataTable dataTable = OracleHelper.Exct_QueryTable(sql);
                if (dataTable != null || dataTable.Rows.Count > 0)
                {
                    dicL3Event.Clear();
                    foreach (DataRow dr in dataTable.Rows)
                    {
                        dicL3Event.Add(dr[fd_eventNo].ToString(), dr[fd_eventCode].ToString());
                    }
                    return dicL3Event;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        ///Deal L3Event with status=1
        /// </summary>
        /// <param name="kvp"></param>
        public static void DealL3Infc_EventByEventCode(KeyValuePair<string, string> kvp)
        {
            try
            {
                switch (kvp.Value)
                {
                    case generalTask:
                        {
                            L3INTF_TASK_INFO.GeneralTask(kvp.Key);
                            break;
                        }
                    case deleteTask:
                        {
                            L3INTF_TASK_DELETE.DeleteTask(kvp.Key);
                            break;
                        }
                    case updateTask:
                        {
                            L3INTF_TASK_INFO.UpdateTask(kvp.Key);
                            break;
                        }
                    case addStripstoTask:
                        {
                            L3INTF_STRIP_INFO.AddStripstoTask(kvp.Key);
                            break;
                        }
                    case deleteStripfromTask:
                        {
                            L3INTF_STRIP_DELETE.DeleteStripfromTask(kvp.Key);
                            break;
                        }
                    case updateStrip:
                        {
                            L3INTF_STRIP_INFO.UpdateStrip(kvp.Key);
                            break;
                        }
                    case checkConnect:
                        {

                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("DealL3Infc_EventByEventCode", ex);
            }
        }


    }
}
